package com.example.coinhelper.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class NoteDBHelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME = UserDBHelper.DATABASE_NAME;
    private static final int DATABASE_VERSION = 1;

    public static final String TABLE_NAME = "notes_table";
    public static final String COLUMN_ID = "id";
    public static final String COLUMN_USERNAME = "username";
    public static final String COLUMN_TITLE = "title";
    public static final String COLUMN_BODY = "body";
    public static final String COLUMN_DATE = "date";

    public static final String SQL_CREATE_TABLE =
            "CREATE TABLE " + TABLE_NAME + " (" +
                    COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
                    COLUMN_USERNAME + " TEXT," +
                    COLUMN_TITLE + " TEXT," +
                    COLUMN_BODY + " TEXT," +
                    COLUMN_DATE + " TEXT," +
                    "FOREIGN KEY (" + COLUMN_USERNAME + ") REFERENCES user_table(username) ON DELETE CASCADE ON UPDATE CASCADE"+
                    ")";

    public NoteDBHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(SQL_CREATE_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // 如果需要更新数据库结构，可以在这里实现升级逻辑
        // 例如：db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
        //       onCreate(db);
    }
}
